package com.ruoyi.project.system.exam.controller;

import java.util.List;

import com.ruoyi.project.system.exam.service.IExamSessionConfigService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.exam.domain.ExamSessionConfig;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.utils.text.Convert;

/**
 * 答题场次配置Controller
 * 
 * @author ruoyi
 * @date 2023-07-16
 */
@Controller
@RequestMapping("/system/exam/config")
public class ExamSessionConfigController extends BaseController
{
    private String prefix = "system/exam/config";

    @Autowired
    private IExamSessionConfigService examSessionConfigService;

    @RequiresPermissions("system:exam:config:view")
    @GetMapping()
    public String config()
    {
        return prefix + "/config";
    }

    /**
     * 查询答题场次配置列表
     */
    @RequiresPermissions("system:exam:config:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ExamSessionConfig examSessionConfig)
    {
        startPage();
        List<ExamSessionConfig> list = examSessionConfigService.selectExamSessionConfigList(examSessionConfig);
        return getDataTable(list);
    }

    /**
     * 导出答题场次配置列表
     */
    @RequiresPermissions("system:exam:config:export")
    @Log(title = "答题场次配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ExamSessionConfig examSessionConfig)
    {
        List<ExamSessionConfig> list = examSessionConfigService.selectExamSessionConfigList(examSessionConfig);
        ExcelUtil<ExamSessionConfig> util = new ExcelUtil<ExamSessionConfig>(ExamSessionConfig.class);
        return util.exportExcel(list, "答题场次配置数据");
    }

    /**
     * 新增答题场次配置
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存答题场次配置
     */
    @RequiresPermissions("system:exam:config:add")
    @Log(title = "答题场次配置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ExamSessionConfig examSessionConfig)
    {
        return toAjax(examSessionConfigService.insertExamSessionConfig(examSessionConfig));
    }

    /**
     * 修改答题场次配置
     */
    @RequiresPermissions("system:exam:config:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ExamSessionConfig examSessionConfig = examSessionConfigService.selectExamSessionConfigById(id);
        mmap.put("examSessionConfig", examSessionConfig);
        return prefix + "/edit";
    }

    /**
     * 修改保存答题场次配置
     */
    @RequiresPermissions("system:exam:config:edit")
    @Log(title = "答题场次配置", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ExamSessionConfig examSessionConfig)
    {
        return toAjax(examSessionConfigService.updateExamSessionConfig(examSessionConfig));
    }

    /**
     * 删除答题场次配置
     */
    @RequiresPermissions("system:exam:config:remove")
    @Log(title = "答题场次配置", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(examSessionConfigService.deleteExamSessionConfigByIds(Convert.toLongArray(ids)));
    }
}